<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />

  <title>Class: CloudShell</title>

  <link rel="stylesheet" href="./rdoc.css" type="text/css" media="screen" />

  <script src="./js/jquery.js" type="text/javascript" charset="utf-8"></script>
  <script src="./js/thickbox-compressed.js" type="text/javascript" charset="utf-8"></script>
  <script src="./js/quicksearch.js" type="text/javascript" charset="utf-8"></script>
  <script src="./js/darkfish.js" type="text/javascript" charset="utf-8"></script>

</head>
<body id="top" class="class">

  <div id="metadata">
    <div id="home-metadata">
      <div id="home-section" class="section">
        <h3 class="section-header">
          <a href="./index.html">Home</a>
          <a href="./index.html#classes">Classes</a>
          <a href="./index.html#methods">Methods</a>
        </h3>
      </div>
    </div>

    <div id="file-metadata">
      <div id="file-list-section" class="section">
        <h3 class="section-header">In Files</h3>
        <div class="section-body">
          <ul>
          
            <li><a href="./lib/cloud_shell_rb.html?TB_iframe=true&amp;height=550&amp;width=785"
              class="thickbox" title="lib/cloud_shell.rb">lib/cloud_shell.rb</a></li>
          
          </ul>
        </div>
      </div>

      
    </div>

    <div id="class-metadata">
      
      <!-- Parent Class -->
      <div id="parent-class-section" class="section">
        <h3 class="section-header">Parent</h3>
        
        <p class="link"><a href="Object.html">Object</a></p>
        
      </div>
      

      

      
      <!-- Namespace Contents -->
      <div id="namespace-list-section" class="section">
        <h3 class="section-header">Namespace</h3>
        <ul class="link-list">
          
          <li><span class="type">CLASS</span> <a href="CloudShell/Context.html">CloudShell::Context</a></li>
          
        </ul>
      </div>
      

      
      <!-- Method Quickref -->
      <div id="method-list-section" class="section">
        <h3 class="section-header">Methods</h3>
        <ul class="link-list">
          
          <li><a href="#method-i-execute_command">#execute_command</a></li>
          
          <li><a href="#method-i-run">#run</a></li>
          
        </ul>
      </div>
      

      
    </div>

    <div id="project-metadata">
      
      
      <div id="fileindex-section" class="section project-section">
        <h3 class="section-header">Files</h3>
        <ul>
        
          <li class="file"><a href="./README_rdoc.html">README.rdoc</a></li>
        
        </ul>
      </div>
      

      <div id="classindex-section" class="section project-section">
        <h3 class="section-header">Class/Module Index
          <span class="search-toggle"><img src="./images/find.png"
            height="16" width="16" alt="[+]"
            title="show/hide quicksearch" /></span></h3>
        <form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
        <fieldset>
          <legend>Quicksearch</legend>
          <input type="text" name="quicksearch" value=""
            class="quicksearch-field" />
        </fieldset>
        </form>

        <ul class="link-list">
        
          <li><a href="./CloudShell.html">CloudShell</a></li>
        
          <li><a href="./CloudShell/Context.html">CloudShell::Context</a></li>
        
          <li><a href="./Configurator.html">Configurator</a></li>
        
          <li><a href="./Formatter.html">Formatter</a></li>
        
          <li><a href="./Object.html">Object</a></li>
        
          <li><a href="./Parser.html">Parser</a></li>
        
          <li><a href="./SwiftClient.html">SwiftClient</a></li>
        
          <li><a href="./SwiftManager.html">SwiftManager</a></li>
        
        </ul>
        <div id="no-class-search-results" style="display: none;">No matching classes.</div>
      </div>

      
    </div>
  </div>

  <div id="documentation">
    <h1 class="class">CloudShell</h1>

    <div id="description" class="description">
      <table class="rdoc-list"><tr><td class="rdoc-term"><p>Author</p></td>
<td>
<p>Murali Raju (&lt;murali.raju@appliv.com&gt;)</p>
</td></tr><tr><td class="rdoc-term"><p>Copyright</p></td>
<td>
<p>Copyright © 2011 Murali Raju.</p>
</td></tr><tr><td class="rdoc-term"><p>License</p></td>
<td>
<p>Apache License, Version 2.0</p>
</td></tr></table>

<p>Licensed under the Apache License, Version 2.0 (the “License”); you may not
use this file except in compliance with the License. You may obtain a copy
of the License at</p>

<p><a
href="http://www.apache.org/licenses/LICENSE-2.0">www.apache.org/licenses/LICENSE-2.0</a></p>

<p>Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an “AS IS” BASIS, WITHOUT
WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
License for the specific language governing permissions and limitations
under the License.</p>

    </div><!-- description -->

    
    
    
    <div id="5Buntitled-5D" class="documentation-section">
      

      

      

      

      <!-- Methods -->
      
      <div id="public-instance-method-details" class="method-section section">
        <h3 class="section-header">Public Instance Methods</h3>

      
        <div id="execute_command-method" class="method-detail ">
          <a name="method-i-execute_command"></a>

          
          <div class="method-heading">
            <span class="method-name">execute_command</span><span
              class="method-args">(command,current_context)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            
            

            
            <div class="method-source-code" id="execute_command-source">
<pre>
<span class="ruby-comment"># File lib/cloud_shell.rb, line 42</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">execute_command</span>(<span class="ruby-identifier">command</span>,<span class="ruby-identifier">current_context</span>)
  <span class="ruby-keyword">case</span> <span class="ruby-identifier">command</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/^ls$/</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-identifier">current_context</span>.<span class="ruby-identifier">to_s</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/^cd (.*$)/</span>
    <span class="ruby-identifier">new_context</span> = <span class="ruby-identifier">current_context</span>.<span class="ruby-identifier">cd</span>(<span class="ruby-node">$1</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">new_context</span>.<span class="ruby-identifier">nil?</span>
      <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;No such key #{$1}&quot;</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">current_context</span> = <span class="ruby-identifier">new_context</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/^cat (.*)$/</span>
    <span class="ruby-identifier">item</span> = <span class="ruby-identifier">current_context</span>.<span class="ruby-identifier">cat</span>(<span class="ruby-node">$1</span>)
    <span class="ruby-keyword">if</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">nil?</span>
      <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;No such item #{$1}&quot;</span>
    <span class="ruby-keyword">else</span>
      <span class="ruby-identifier">puts</span> <span class="ruby-identifier">item</span>.<span class="ruby-identifier">inspect</span>
    <span class="ruby-keyword">end</span>
  <span class="ruby-keyword">when</span> <span class="ruby-regexp">/^help$/</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;cat &lt;item&gt; - print the contents of &lt;item&gt; in the current context&quot;</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;cd  &lt;item&gt; - change context to the context of &lt;item&gt;&quot;</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;cd  ..     - change up one level&quot;</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;ls         - list available items in the current context&quot;</span>
    <span class="ruby-identifier">puts</span> <span class="ruby-string">&quot;exit    - exit shell&quot;</span>
  <span class="ruby-keyword">end</span>
  <span class="ruby-identifier">current_context</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- execute_command-source -->
            
          </div>

          

          
        </div><!-- execute_command-method -->

      
        <div id="run-method" class="method-detail ">
          <a name="method-i-run"></a>

          
          <div class="method-heading">
            <span class="method-name">run</span><span
              class="method-args">(json_file)</span>
            <span class="method-click-advice">click to toggle source</span>
          </div>
          

          <div class="method-description">
            
            <p>A basic read-only shell-like interface for browsing S3 or Swift JSON
objects via fog.to_json using readline</p>
            

            
            <div class="method-source-code" id="run-source">
<pre>
<span class="ruby-comment"># File lib/cloud_shell.rb, line 24</span>
<span class="ruby-keyword">def</span> <span class="ruby-identifier">run</span>(<span class="ruby-identifier">json_file</span>)
  <span class="ruby-identifier">root</span> = <span class="ruby-constant">JSON</span>.<span class="ruby-identifier">parse</span>(<span class="ruby-identifier">json_file</span>)
  <span class="ruby-identifier">command</span> = <span class="ruby-keyword">nil</span>

  <span class="ruby-identifier">current_context</span> = <span class="ruby-constant">Context</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">root</span>,<span class="ruby-keyword">nil</span>)

  <span class="ruby-constant">Readline</span>.<span class="ruby-identifier">completion_proc</span> = <span class="ruby-identifier">proc</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">input</span><span class="ruby-operator">|</span>
<span class="ruby-identifier">current_context</span>.<span class="ruby-identifier">completions</span>(<span class="ruby-identifier">input</span>)
  }

  <span class="ruby-keyword">while</span> <span class="ruby-identifier">command</span> <span class="ruby-operator">!=</span> <span class="ruby-string">'exit'</span>
    <span class="ruby-identifier">command</span> = <span class="ruby-constant">Readline</span>.<span class="ruby-identifier">readline</span>(<span class="ruby-string">&quot;swift&gt; &quot;</span>,<span class="ruby-keyword">true</span>)
    <span class="ruby-keyword">break</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">command</span>.<span class="ruby-identifier">nil?</span>
    <span class="ruby-identifier">current_context</span> = <span class="ruby-identifier">execute_command</span>(<span class="ruby-identifier">command</span>.<span class="ruby-identifier">strip</span>,<span class="ruby-identifier">current_context</span>)
  <span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
            </div><!-- run-source -->
            
          </div>

          

          
        </div><!-- run-method -->

      
      </div><!-- public-instance-method-details -->
    
    </div><!-- 5Buntitled-5D -->
  

  </div><!-- documentation -->

  <div id="validator-badges">
    <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
    <p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
      Rdoc Generator</a> 2</small>.</p>
  </div>

</body>
</html>

